home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_11 / nelson / block.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-12  |  3.6 KB  |  104 lines

  1. /* ----------------------------------------------------
  2.  *  block.h
  3.  *
  4.  *  IOCTL for block devices
  5.  * ------------------------------------------------- */
  6.  
  7. #ifndef  __BLOCK_H
  8. #define  __BLOCK_H
  9.  
  10. #include <ctype.h>      //toupper()
  11. #include "iostruct.h"
  12. #include "iobase.h"
  13.  
  14. //Converts ASCII drive letter designator ('A') to
  15. //IOCTL "1-Based" drive numbers, which maps drive A:
  16. //to 1, B = 2, etc. and uses 0 as the default drive.
  17. //
  18. #define DRIVE_CODE(d)   ((toupper(d)-'A')+1)
  19. #define DEFAULT_DRIVE   0
  20.  
  21. class IoctlBlock : public IoctlBase  {
  22.  
  23. protected:
  24.     unsigned drive_info( int drive );
  25.     int block_ioctl( block_cmd, void * );
  26.     unsigned ioctl_data( ioctl_cmd, unsigned, void *);
  27.     int format_track( int, int, int );
  28.     IoctlBlock(int drive);      //constructor
  29.     void IoctlError( int );
  30.     int _drive;     //current drive (1-based)
  31.     unsigned _info;    //current drive info word
  32.  
  33. public:
  34.     static IoctlBlock *Init( int drive );
  35.     ~IoctlBlock() { }
  36.  
  37.     enum localDrive   {
  38.     //bit settings for local drives, i.e. bit 12=0....
  39.     _32bit = 0x0002,    //b1=1, drive uses 32-bit
  40.                         //sector addressing
  41.     genBlockIoctl = 0x0040, //b6=1, can use GIOCTL for
  42.                 //block devices (440dh) and
  43.                 //and get/set logical drive
  44.                 //map (440eh and 440fh)
  45.     queryIoctl = 0x0080, //b7=1, can use Query IOCTL
  46.              //Device (4411h)
  47.     isShared = 0x0200,   //b9=1, drive local but shared
  48.              //by others on network
  49.     rmvMedia = 0x0800,   //b11=1, can use Removable
  50.              //media check (4408h)
  51.     drvRemote = 0x1000,  //b12 = 1 if drive is remote
  52.     mdFat = 0x2000,      //b13=1, needs FAT media descr
  53.     xmitIoctl = 0x4000,  //b14=1, can send/recv
  54.                          //Ioctl data to/from block
  55.                          //device (4404h and 4405h)
  56.     substDrive = 0x8000  //b15=1, substitution drive
  57.                          //set by 'subst' command
  58.     };
  59.  
  60.     //Return values for checkFunction() ......
  61.     enum query_return_t   {
  62.         is_supported,      //OK!
  63.         invalid_function,  //no IOCTL support at all
  64.         access_denied,     //function not supported
  65.         invalid_drive,
  66.         unknown            //unable to comply, or
  67.                            //_dos_version < 5.0
  68.         };
  69.  
  70.     unsigned driveInfo( void ) { return _info; }
  71.     int currentDrive(void ) { return _drive; }
  72.     int sendIoctl( unsigned *count, void *buffer );
  73.     int readIoctl( unsigned *count, void *buffer );
  74.     int isRemote(void) { return _info & drvRemote; }
  75.     int isRemovable(void);
  76.     int checkAlias( void);
  77.     int nextAlias( int next );
  78.     int getParams( struct DEVICEPARAMS *dpms );
  79.     int setParams( struct DEVICEPARAMS *dpms );
  80.     int readSectors( struct RWBLOCK *tpms );
  81.     int writeSectors( struct RWBLOCK *tpms );
  82.     int getAccessFlag(void);
  83.     int setAccessFlag(int flag);
  84.     int formatTrack( int head, int cyl );
  85.     int checkFormat( int head, int cyl )
  86.         { return format_track( 1, head, cyl );  }
  87.     int verifyTrack( int head, int cyl );
  88.     int getMediaID( struct MID *mid )     {
  89.         return block_ioctl( get_media_id,
  90.                             (void *) mid );  }
  91.     int setMediaID( struct MID *mid )     {
  92.         return block_ioctl( set_media_id,
  93.                             (void *) mid );  }
  94.     int senseMediaType( struct MTYPE *mtype )   {
  95.         return block_ioctl( sense_media_type,
  96.                             (void *) mtype   );  }
  97.     int checkFunction( block_cmd cmd );
  98.  
  99. };  //.... end class IoctlBlock
  100.  
  101. #endif   //__BLOCK_H
  102.  
  103. /* ----- End of File ------------------------------- */
  104.